<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>库存查询</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
    <style type="text/css">
        .layui-form-select dl {
            max-height: 180px;
        }
    </style>
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">药品名称:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" placeholder="请输入药品名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">药品类型:</label>
                    <div class="layui-input-inline">
                        <select id="drugType" name="drugType">
                            <option value="">请选择药品类型</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">生产厂家:</label>
                    <div class="layui-input-inline">
                        <select id="production" name="production">
                            <option value="">请选择生产厂家</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">处方类型:</label>
                    <div class="layui-input-inline">
                        <select id="preType" name="preType">
                            <option value="">请选择处方类型</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="drugInfo-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>


<!--数据表格-->
<div class="layui-card">
    <div class="layui-card-body">
        <table id="drugInfo-table" lay-filter="drugInfo-table"></table>
    </div>
</div>


<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;

        //加载药品类型的下拉框
        $.get("/drugInfo/loadDrugType", function (data) {
            let drugType = $("#drugType");
            let html = '<option value="">药品类型</option>'
            $.each(data.data, function (i, item) {
                html += '<option value="' + item.id + '">' + item.name + '</option>'
            });
            drugType.html(html);
            form.render();
        });


        //加载生产厂家的下拉框
        $.get("/drugInfo/loadProduction", function (data) {
            let production = $("#production");
            let html = '<option value="">药品类型</option>'
            $.each(data.data, function (i, item) {
                html += '<option value="' + item.id + '">' + item.name + '</option>'
            });
            production.html(html);
            form.render();
        });

        //加载处方类型的下拉框
        $.get("/drugInfo/loadPreType", function (data) {
            let preType = $("#preType");
            let html = '<option value="">药品类型</option>'
            $.each(data.data, function (i, item) {
                html += '<option value="' + item.id + '">' + item.name + '</option>'
            });
            preType.html(html);
            form.render();
        });

        let cols = [
            [
                {
                    title: '药品ID',
                    field: 'id',
                    hide: true,
                    align: 'center',
                },
                {
                    title: '药品名称',
                    field: 'name',
                    align: 'center'
                },
                {
                    title: '库存量',
                    field: 'inventory',
                    align: 'center',
                },
                // {
                //     title: '预警值',
                //     field: 'early',
                //     align: 'center',
                // },
                {
                    title: '生产厂家',
                    field: 'productionName',
                    width: 220,
                    align: 'center',
                },
                {
                    title: '药品类型',
                    field: 'drugTypeName',
                    align: 'center',
                },
                {
                    title: '处方类型',
                    field: 'preTypeName',
                    align: 'center',
                },
                {
                    title: '单位',
                    field: 'company',
                    align: 'center',
                },

                {
                    title: '换算量',
                    field: 'conversion',
                    align: 'center',
                }
            ]
        ]

        var tableIns = table.render({
            elem: '#drugInfo-table',
            url: '/drugInfo/loadAllDrugInfoPage',
            page: true,
            cols: cols,
            toolbar: '#drugInfo-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print'],
            response: {
                statusCode: 200
            },
            done: function (res, curr, count) {
                if (res.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: (curr - 1)
                        }
                    });
                }
            },
        });

        //表头监听
        table.on('toolbar(drugInfo-table)', function (obj) {
            if (obj.event === 'refresh') {
                window.refresh();
            }
        });

        //表格监听
        form.on('submit(drugInfo-query)', function (data) {
            table.reload('drugInfo-table', {
                where: data.field
            })
            return false;
        });


        window.refresh = function (param) {
            table.reload('drugInfo-table');
        }

    })
</script>
</body>
</html>
